/* 
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
function Sprite(scene)
{
    this.scene = scene;
    this.X = 05;
    this.Y = 05;
    this.W = 24;
    this.H = 24;
    this.speed = 4.5;
    this.image = 
            [ new Image(this.W, this.H) ];
    a=1;
    b=1;
    this.image[0].src = "img/ball_small.png";
    this.Draw = function()
    {
        this.scene.Context.fillStyle = 'rgba(1,1,1,1)';        
            this.scene.RotateAt(a, this.X+this.W/2, this.Y+this.H/2 );
            this.scene.Context.drawImage(this.image[0], this.X,this.Y);
            this.scene.RotateAt(-a, this.X+this.W/2, this.Y+this.H/2 );        
        this.scene.Context.fillStyle = 'rgba(0,0,0,1)';
        
        
    };
    //<editor-fold defaultstate="collapsed" desc="move">
    this.moveUP = function() {
        var y = this.Y - this.speed;
        if (y < 0)
            y = 0;
        if(this.canMove(this.X, y))
                this.Y= y;
    };
    this.moveDOWN = function() {
        var y = this.Y + this.speed;
        if (y > this.scene.Context.canvas.clientHeight-this.H)
            y = this.scene.Context.canvas.clientHeight-this.H;
        if(this.canMove(this.X, y))
            this.Y=y;
    };
    this.moveLEFT = function() {
        var x = this.X - this.speed;
        if (x < 0)
            x = 0;
        if(this.canMove(x, this.Y))
            this.X=x;
    };
    this.moveRIGHT = function() {
        var x = this.X + this.speed;
        if (x > this.scene.Context.canvas.clientWidth-this.W)
            x = this.scene.Context.canvas.clientWidth-this.W;
        if(this.canMove(x, this.Y))
            this.X=x;
    };
    
    this.canMove = function (x,y)
    {        
        var value = this.scene.maze.canMove(x,y,this.W+x,this.H+y);        
        switch(value)
        {
            case -1:
                var maxS = 12;
                this.speed+=0.01;
                this.speed*=1.1;
                if(this.speed>maxS) this.speed=maxS;
                break;
            case 0:
                var diff = 8-this.speed;
                this.speed+=diff/100;
                break;
            case 1:
                var diff = 2-this.speed;
                this.speed+=diff/13;
                break;
            case 2:
                this.speed*=0.95;
                if(this.speed<0.1)
                    this.speed=0.1;
                break;
                
                    
        }
        a+=this.speed;
        return (value<2);
    };
    //</editor-fold>

}